package com.tdrc.common.controller;

import com.alibaba.fastjson.JSON;
import com.tdrc.common.beans.Menu;
import com.tdrc.common.service.MenuService;
import com.tdrc.common.util.JsonResult;
import com.tdrc.common.beans.ResultCode;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

/**
 * @author dpf
 * @version 1.0
 * @date 2020-4-1 15:55
 * @instruction ...
 */
@RestController
@RequestMapping("/menu")
public class MenuController extends BaseController {
    @Resource
    private HttpServletRequest request;
    @Resource
    private MenuService menuService;
    @Value("${general.parameter.topMenuId}")
    private   int TOP_MENU_ID;

    /**
     * 前端左侧树菜单
     *
     * @return
     */
    @GetMapping("/nav")
    public Object list(Integer userId) {
        return new JsonResult(ResultCode.OK, menuService.menuNav(userId));
    }

    @GetMapping("/treeMenu")
    public Object treeMenu(String menuName) {
        return new JsonResult(ResultCode.OK, menuService.treeMenu(TOP_MENU_ID, menuName));
    }

    @GetMapping("/listMMenu")
    public Object listMMenu() {
        return new JsonResult(ResultCode.OK, menuService.listMMenu());
    }

    @PostMapping("/add")
    public Object add(@RequestBody Menu menu) {
        menuService.addMenu(menu);
        return new JsonResult(ResultCode.OK);
    }

    @PostMapping("/update")
    public Object update(@RequestBody Menu menu) {
        menuService.updateMenu(menu);
        return new JsonResult(ResultCode.OK);
    }

    @DeleteMapping("/delete/{id}")
    public Object deleteMenu(@PathVariable Integer id) {
        menuService.deleteMenu(id);
        return new JsonResult(ResultCode.OK);

    }

}
